// 云函数入口文件
const cloud = require('wx-server-sdk')

cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

// 云函数入口函数
exports.main = async (event, context) => {
  try {
    const db = cloud.database()
    
    // 为gift_list集合创建索引
    await db.collection('gift_list').createIndex({
      indexes: [{
        name: 'openid_1',
        unique: false,
        key: {
          openid: 1
        }
      }]
    })
    
    return {
      success: true,
      message: '索引创建成功'
    }
  } catch (error) {
    return {
      success: false,
      message: '索引创建失败',
      error: error
    }
  }
} 